package org.langqiao.thread;

public class SyncDubbo2 {
	static class Main{
		public int i = 10;
		public synchronized void operateSup(){
			try {
				i --;
				System.out.println("main print i="+i);
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	static class Sub extends Main{
		
		public synchronized void operateSub(){
			while(i>0){
				i--;
				System.out.println("sub print i="+i);
				this.operateSup();
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	public static void main(String[] args) {
		final Sub sub = new Sub();
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				sub.operateSub();
			}
		});
		Thread t2 = new Thread(new Runnable() {
			public void run() {
				sub.operateSub();
			}
		});
		t1.start();
		t2.start();		
	}
}
